Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@littlemissrobot/sass-functions
Advanced tools
Little Miss Robot sass functions library that helps execute reusable and complex tasks
This repository contains Sass (Dart Sass) based functions that we, at Little Miss Robot, like to use to make our wonderful lives in the world of SASS more wondeful. These functions are also mainly used throughout our other libraries to manage recurring tasks.
This package does not contain or generate any CSS. It simply provides a couple
of @function
statements for you to make use of.
This library makes use of Dart Sass, which is the primary implementation of Sass. Make sure that your Sass compiler is making use of Dart Sass.
This means that if you are using a task manager (like Gulp) or a module bundler (like Webpack), you must indicate which compiler it should use for compiling Sass to CSS.
Furthermore, this library makes heavy use of Sass modules:
@use
. Therefore we
recommend importing and using this library with the @use
statement.
# As a dependency
$ npm install @littlemissrobot/sass-functions
# As a dev-dependency
$ npm install --save-dev @littlemissrobot/sass-functions
@use "YOUR-PATH-TO-NODE_MODULES/@littlemissrobot/sass-functions" as _functions;
_functions
namespace:h1 {
margin-bottom: _functions.px_rem(16px);
}
map
are namespaced with
_functions.map_[FUNCTION-NAME]
or a list
would be _functions.list_[FUNCTION-NAME]
.@use "YOUR-PATH-TO-NODE_MODULES/@littlemissrobot/sass-functions/px" as _px;
_px
namespace:h1 {
margin-bottom: _px.rem(16px);
}
That's (mind-blowingly) it! There are a number of partials to use the functions from:
"sass-functions/list" as _list;
"sass-functions/map" as _map;
"sass-functions/math" as _math;
"sass-functions/number" as _number;
"sass-functions/px" as _px;
"sass-functions/rem" as _rem;
"sass-functions/string" as _string;
These functions are namespace with list_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.list_includes($list, 5);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/list" as _list;
_list.includes($list, 5);
Checks if the list contains a certain item. Returns a boolean.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list: (1, 2, 3, 4, 5);
_list.includes($list, 5); // true
_list.includes($list, 10); // false
Checks if the numbers in the list are ordered lowest to highest.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list1: (2, 1, 3);
$list2: (1, 2, 3);
_list.is-low-to-high($list1); // false
_list.is-low-to-high($list2); // true
Merges multiple lists and removes any duplicates.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list1: (1, 2, 3);
$list2: (1, 2, 3, 4, 5);
$list3: (4, 5, 6, 7, 8);
_list.merge-unique($list1, $list2, $list3); // (1, 2, 3, 4, 5, 6, 7, 8)
Loops through the list and removes duplicate values.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list: (1, 2, 3, 1, 3, 4, 5);
_list.remove-duplicates($list); // (1, 2, 3, 4, 5)
Reverses the order of the values within a list.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list: (1, 2, 3, 4, 5);
_list.reverse($list); // (5, 4, 3, 2, 1)
Sorts a list of numbers from lowest to highest.
Parameters:
@use "@littlemissrobot/sass-functions/list" as _list;
$list: (2, 1, 5, 3, 4);
_list.sort-low-to-high($list); // (1, 2, 3, 4, 5)
These functions are namespace with map_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.map_includes($map, color);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/map" as _map;
_map.includes($map, color);
The standard map-merge function only lets you merge 2 maps. This function makes use of the method, but merges as many maps together as you want.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$map1: (
display: flex;
justify-content: center,
align-items: center,
);
$map2: (
font-size: 16px,
line-height: 24px,
);
$map3: (
color: white,
background-color: black,
);
_map.sort-low-to-high($map1, $map2, $map3);
// result: (
// display: flex;
// justify-content: center,
// align-items: center,
// font-size: 16px,
// line-height: 24px,
// color: white,
// background-color: black,
// );
Retrieve a value from a map which can contain mulitple more maps with values. Pass a path as a string, where each key is seperated by a space. Each key within that string represents the keys until you reach a certain value within the map.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$colors: (
brand: (
primary: black,
secondary: white
),
typo: (
title: (
h1: black,
h2: red,
h3: blue
),
text: (
p: black,
small: (
base: gray,
inverse: white,
),
)
)
);
_map.get($colors, "brand primary"); // black
_map.get($colors, "typo title h1"); // black
_map.get($colors, "typo text small base"); // gray
Generate a new map of items, based on the values within the list, which represent the keys in the map.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
$list1: (viewport-7, viewport-9);
$list2: (viewport-3, viewport-9, viewport-12);
_map.get-from-list($breakpoints, $list1);
// result: (
// viewport-7: 720px,
// viewport-9: 992px,
// );
_map.get-from-list($breakpoints, $list2);
// result: (
// viewport-3: 360px,
// viewport-9: 992px,
// viewport-12: 1200px,
// );
Generate a new list of keys from a map, based on the items within a map and a list representing the values in that map.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
$list1: (720px, 992px);
$list2: (360px, 992px, 1200px);
_map.get-keys-from-list($breakpoints, $list1);
// result: (viewport-7, viewport-9);
_map.get-keys-from-list($breakpoints, $list2);
// result: (viewport-3, viewport-9, viewport-12);
Generate a new list of values from a map, based on the items within a map and a list representing the keys in that map.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
$list1: (viewport-7, viewport-9);
$list2: (viewport-3, viewport-9, viewport-12);
_map.get-values-from-list($breakpoints, $list1);
// result: (720px, 992px);
_map.get-values-from-list($breakpoints, $list2);
// result: (360px, 992px, 1200px);
Checks if a map contains a certain key.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
_map.includes($breakpoints, viewport-7); // true
_map.includes($breakpoints, viewport-2); // false
Checks if the numbers, as values, in the map are ordered lowest to highest.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$map1: (
viewport-7: 720px,
viewport-3: 360px,
viewport-9: 960px
);
$map2: (
viewport-3: 360px,
viewport-7: 720px,
viewport-9: 960px
);
_map.is-low-to-high($map1); // false
_map.is-low-to-high($map2); // true
Reverses the order of the items within a map.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
_map.reverse($breakpoints);
// result: (
// viewport-12: 1200px
// viewport-9: 992px,
// viewport-7: 720px,
// viewport-4: 480px,
// viewport-3: 360px,
// );
Trims a map to a certain target key. Returns a new map that is trimmed down until the key is met.
Parameters:
@use "@littlemissrobot/sass-functions/map" as _map;
$breakpoints: (
viewport-3: 360px,
viewport-4: 480px,
viewport-7: 720px,
viewport-9: 992px,
viewport-12: 1200px
);
_map.trim($breakpoints, viewport-7);
// result: (
// viewport-3: 360px,
// viewport-4: 480px,
// viewport-7: 720px
// );
These functions are namespace with math_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.math_pow(8, 2);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/math" as _math;
_math.pow(8, 2);
Round a number's value after the comma (decimals) to a certain amount.
Parameters:
@use "@littlemissrobot/sass-functions/math" as _math;
_math.decimal(1.12345, 2); // 1.12
_math.decimal(1.123456789, 5); // 1.12346
Power function / exponent operator which accepts positive, negative (integer, float) exponents.
Parameters:
@use "@littlemissrobot/sass-functions/math" as _math;
_math.pow(2, 8); // 256
_math.pow(4, 2); // 16
These functions are namespace with number_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.number_strip(16px);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/number" as _number;
_number.strip(16px);
Check if a number is of type integer (no decimals).
Parameters:
@use "@littlemissrobot/sass-functions/number" as _number;
_number.is-int("sass-functions"); // false
_number.is-int(20); // true
_number.is-int(20.5); // false
Generate a random number between a minimum and maximum value.
Parameters:
@use "@littlemissrobot/sass-functions/number" as _number;
_number.randomize(0, 10); // 4
_number.is-int(0, 10); // 5
_number.is-int(2, 8); // 6
_number.is-int(2, 8); // 7
Removes the unit from a value.
Parameters:
@use "@littlemissrobot/sass-functions/number" as _number;
_number.strip(10px); // 10
_number.strip(7rem); // 7
Checks whether or not the passed value is a number. Very similar to is-int, but this value can have decimals.
Parameters:
@use "@littlemissrobot/sass-functions/number" as _number;
_number.valid(10px); // true
_number.valid(7rem); // true
_number.valid(2.5px); // true
_number.valid("sass-functions"); // false
_number.valid(center); // false
These functions are namespace with string_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.string_includes("Functions", "F");
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.includes("Functions", "F");
Escapes a value and adds extra slashes to special characters. This can be useful for creating a class with special characters.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.escape(100%); // 100\%
_string.escape(l-grid__col:12/12); // l-grid__col\:12\/12
Check if string contains certain characters. Returns a boolean.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.escape(100%); // 100\%
_string.escape(l-grid__col:12/12); // l-grid__col\:12\/12
Replace a certain part of a string by another string.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.replace("sass-functions", "sass", "dart-sass"); // dart-sass-functions
Create a list from a string by defining a character to split the string at.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.split("sass-functions", "-"); // (sass, functions)
Converts a value to a string
Parameters:
@use "@littlemissrobot/sass-functions/string" as _string;
_string.to(10px); // "10px"
These functions are namespace with px_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.px_rem(16px);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/px" as _px;
_px.rem(16px);
Converts a pixel value to em.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _px;
_px.em(16px); // 1em
_px.em(10px, 16px); // 0.625em
_px.em(32px); // 2em
_px.em(20px, 10px); // 2em
Converts a pixel value to rem.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _px;
_px.rem(16px); // 1rem
_px.rem(10px, 16px); // 0.625rem
_px.rem(32px); // 2rem
_px.rem(20px, 10px); // 2rem
These functions are namespace with rem_:
@use "@littlemissrobot/sass-functions" as _functions;
_functions.rem_px(1rem);
Or can be included through the partial:
@use "@littlemissrobot/sass-functions/rem" as _rem;
_rem.px(1rem);
Converts a rem value to px.
Parameters:
@use "@littlemissrobot/sass-functions/string" as _rem;
_rem.px(1rem); // 16px
_rem.px(2rem); // 32px
_rem.px(1rem, 10px); // 10px
_rem.px(2rem, 10px); // 20px
FAQs
Little Miss Robot sass functions library that helps execute reusable and complex tasks.
The npm package @littlemissrobot/sass-functions receives a total of 55 weekly downloads. As such, @littlemissrobot/sass-functions popularity was classified as not popular.
We found that @littlemissrobot/sass-functions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.